package com.lzq.aopdemo.proxy;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class DynamicMain {
    //jdk动态代理
//    public static void main(String[] args) {
//        HouseSubject target= new RealHouseSubject();
//        //创建⼀个代理类：通过被代理类、被代理实现的接⼝、⽅法调⽤处理器来创建
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(
//                target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class},
//                new JDKInvocationHandler(target)
//        );
//        proxy.rentHouse();
//    }

    //cglib动态代理
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
        //创建⼀个代理类：通过被代理类、被代理实现的接⼝、⽅法调⽤处理器来创建
        HouseSubject proxy = (HouseSubject)
                Enhancer.create(target.getClass(),new CGLIBInterceptor(target));
        proxy.rentHouse();
    }
}
